import { createRouter, createWebHashHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const routerArray = [] as any[]
const obj = import.meta.glob('./*.route.ts')
const routes = Object.values(obj)
for (let i = 0; i < routes.length; i++) {
  const route = (await routes[i]()) as any
  route.default.forEach((a: any) => routerArray.push(a))
}

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    ...routerArray,
    {
      path: '/',
      name: 'home',
      component: HomeView
    },
    {
      path: '/about',
      name: 'about',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/AboutView.vue')
    },
    {
      path: '/history',
      name: 'HistoryView',
      component: () => import('@views/HistoryView.vue')
    }
  ]
})

export default router
